﻿using System.Windows;
using System.Windows.Controls;

using DevEnverModal;

namespace ModalWizard
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            btShowWizard.Click += OnShowWizardClick;
            btShowDialog.Click += OnShowDialogClick;

            ModalControl.ParentHost = LayoutRoot;
        }

        void OnShowDialogClick(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(
                "Some modal title", 
                "This is some very very very very very very very very very very very very very very very very... long made up error message!", 
                MessageBox.Buttons.YesNo, MessageBox.Icons.Information, OnDialogClosed);       
        }

        bool OnDialogClosed(object sender, ExitCode e)
        {
            _txtMsg.Text = "Dialog Closed with code: " + e;
            return true;
        }

        ModalControl _oModalCtrl = new ModalControl();

        void OnShowWizardClick(object sender, RoutedEventArgs e)
        {
            Wizard oWizard = new Wizard();
            oWizard.DataContext = LayoutRoot.DataContext;
            oWizard.Pages.Add(new WizardPage1());
            oWizard.Pages.Add(new WizardPage2());
            oWizard.Pages.Add(new WizardPage3());

            oWizard.PageEvent += new WizardPageEvent(OnPageEvent);

            _oModalCtrl.ShowModal(oWizard);          
        }

        void OnPageEvent(Wizard sender, WizardEventArgs e)
        {
            _txtMsg.Text = string.Format("Action: {0}, Current: {1}, New: {2}", 
                e.Action, e.CurrentPageIndex, e.NewPageIndex);

            if(e.Action == WizardAction.Finish)
            {
                // Close the wizard
                Wizard oWizard = (Wizard)_oModalCtrl.HideModal();
            }
        }
    }
}
